package androidTest.test;

public class RotationDegree{
	
	private float x = -1.0f;
	private final float threshold = 2.0f;
	float deg1, deg2, deg;
    
    
    public float degree(float accMagOrientation) {
    	x = (accMagOrientation + 180.0f) %360;  // 0,360:south  180:north
    	if (x < 0) {
    		deg1 = x;
    	}
    	else if (Math.abs(deg1-x) > threshold) {
    		deg2 = x;
    		deg = (deg2+360.0f - deg1)%360;
    		deg1 = deg2;
    	}
    	
    	return deg; //return the degree of clockwise rotation(0~359)
    }
}